package com.ug_project.objects

/**
 * Created by Administrator on 2/17/2017.
 */

infix fun <T> T?.isNotNull(action: (T) -> Unit) : Unit {
    if (this.isNotNull) action(this!!)
}

infix fun <T> T?.isNull(action: () -> Unit) : Unit {
    if (this.isNull) action()
}

/*قۇرۇق بولسا*/
val <T> T.isNull: Boolean
get() {
    return try {
        if (this == null) true
        else {
            false
        }
    }
    catch (exception: Exception)
    {
        true
    }
}

val <T> T.isNotNull: Boolean
    get() {return !this.isNull}

infix fun <T> Array<T>.aggregateToString(split_string: String) : String = this.toArrayList().aggregateToString(split_string)
infix fun <T> List<T>.aggregateToString(split_string: String) : String
{
    var temp = ""
    for (index in this.indices)
    {
        temp += this[index].toString()
        if (index < size - 1)
            temp += split_string
    }
    return temp
}

fun <T> Array<T>.toArrayList() : ArrayList<T>
{
    var arraylist = ArrayList<T>()
    arraylist.addAll(this)
    return arraylist
}

fun <T> List<T>.toArrayList() : ArrayList<T>
{
    var arraylist = ArrayList<T>()
    arraylist.addAll(this)
    return arraylist
}